﻿@using PNProject
@using PNProject.EF;
@{
    Layout = null;
    bool lang = (bool)(ViewData["lang"]);
    string langText = lang ? "" : "en-US/";
    List<News> news = (List<News>)ViewData["news"];
    List<Feedback> feedbacks = (List<Feedback>)ViewData["questions"];
    List<Support> supports = (List<Support>)ViewData["supports"];
}

<div class="newshome">
    @{
        string title1 = "";
        title1 = lang ? "Tin tức & sự kiện" : "News & events";
        string xem1 = "";
        xem1 = lang ? "Xem tất cả" : "View all";
    }
    <div class="tthome">
        <p>@this.LocalResources("title1")</p>
        <a href="/@string.Concat(langText, "news")">@this.LocalResources("Viewall")</a></div>
    <div class="cchome">
        <div class="boxnewshome">
            <ul>
                @foreach (var item in news)
                {
                    <li>
                        <a href="/@string.Concat(langText, "news/detail/", item.TLink)">@item.Title</a>
                        <p>@item.Short</p>
                    </li>
                }

            </ul>
        </div>
    </div>
</div>
<div class="hotro">
    <div class="yahoo">
         <span style="color: #fb7600;">@this.LocalResources("Support")</span><span style="color: #00fff6;">@this.LocalResources("Online")</span>
        <ul>

            @foreach (var item in supports)
            {

                if (item.Type == true)
                {
                    <li>
                        <a class="online yahoo_support" href="ymsgr:sendim?@item.Nick">
                            <img alt="@item.Nick" class="support_img" src="/Images/yahoo_offline.png"/></a>
                        @if (lang)
                        {
                            <p>@item.Name</p>
                        }
                        else
                        {
                            <p>@item.Description</p>
                        }
                    </li>
                }
                else
                {
                    <li>
                        <a class="online skype_support" href="Skype:@item.Nick?chat">
                            <img alt="@item.Nick" class="support_img" src="/Images/skype_offline.png"/></a>
                        @if (lang)
                        {
                            <p>@item.Name</p>
                        }
                        else
                        {
                            <p>@item.Description</p>
                        }
                    </li>
                }

            }
        </ul>
    </div>
    <!--yahoo-->
    <div class="hotline">
        <ul>
            <li>
                <p>0903 644 504</p>
            </li>
            <li>
                <p>0979 739 901</p>
            </li>
        </ul>
    </div>
</div>
<div class="hoidaphome">
    <div class="tthome">
        <p class="home-1">@this.LocalResources("title2")</p>
        <a href="/@string.Concat(langText, "qa")">@xem1</a></div>
    <div class="cchome">
        <div class="cauhoi">
            <ul>
                @foreach (var item in feedbacks)
                {
                    <li><a href="/@string.Concat(langText, "QA/Detail/", item.FeedbackID.ToString())">@item.Title</a></li>
                }

            </ul>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var url = "/api/publicapi/CheckSupportStatus?nick={nick}&type={type}";
        var skylist = $(".skype_support");
        var yahoolist = $(".yahoo_support");
        for (var i = 0; i < skylist.length; i++) {
            var nick = $(skylist[i]).find("img").attr("alt");
            CheckStatus(nick, "0", i, function (data, index) {
                $(skylist[index]).find("img").remove();
                if (data == "nok") {
                    $(skylist[index]).append("<img class=\"support_img\" src=\"/Images/skype_offline.png\"/>");
                }
                else {
                    $(skylist[index]).append("<img class=\"support_img\" src=\"/Images/skype_online.png\"/>");
                }
            });
        }

        for (var i = 0; i < yahoolist.length; i++) {
            var nick = $(yahoolist[i]).find("img").attr("alt");
            CheckStatus(nick, "1", i, function (data, index) {
                $(yahoolist[index]).find("img").remove();
                if (data == "nok") {
                    $(yahoolist[index]).append("<img class=\"support_img\" src=\"/Images/yahoo_offline.png\"/>");
                }
                else {
                    $(yahoolist[index]).append("<img class=\"support_img\" src=\"/Images/yahoo_online.png\"/>");
                }
            });
        }



        function CheckStatus(nick, type, index, callback) {
            var checkURL = "";
            if (type == "1") {
                checkURL = url.replace("{nick}", nick).replace("{type}", "1");
            }
            else {
                checkURL = url.replace("{nick}", nick).replace("{type}", "0");
            }
            $.ajax({
                url: checkURL
            }).done(function (data) {
                callback(data, index);
            });
        }
    });
</script>
